'use strict'

const bcrypt = require('bcrypt-promise')
// const fs = require('fs-extra')
// const mime = require('mime-types')
const sqlite = require('sqlite-async')
// const query = require('../config/connection');
const saltRounds = 10

//error answer score = 0
// {id, question_id, choicename, isright}
module.exports = class AnswerChoice {

	constructor(dbName = 'website.db') {
		return (async() => {
			this.db = await sqlite.open(dbName)
			return this
		})()
	}

	async listALl() {
		try {
			let sql = `SELECT * FROM answerchoices;`
			const data = await this.db.all(sql)
			return data
		} catch(err) {
			throw err
		}
	}

	async getOne(id) {
		try {
			let sql = `SELECT * FROM answerchoices where id = ${id};`
			const data = await this.db.get(sql)
			return data
		} catch(err) {
			throw err
		}
	}

	async listAnswerChoinceByQuestionId(questionId) {
		try {
			let sql = `SELECT * FROM answerchoices where question_id = ${questionId};`
			const data = await this.db.all(sql)
			return data
		} catch(err) {
			throw err
		}
	}

}
